package com.hjj.advice;

import com.powernode.commons.Result;
import com.powernode.commons.ResultException;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@Component
@ControllerAdvice
public class Advice {

    @ResponseBody
    @ExceptionHandler(value = ResultException.class)
    public Result ex(Exception e){
        if (e instanceof ResultException){
            ResultException resultException = (ResultException)e;
            return Result.build(resultException);
        }else {
            e.printStackTrace();
        }
        return null;
    }
}
